{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">模块管理</div>
    <div class="layui-card-body">
        <table class="layui-hide" id="table" lay-filter="table"></table>
    </div>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" id="local-install">本地安装</a>
        </div>
    </script>
    <script type="text/html" id="titleTpl">
    {{#  if(d.installtime == "" || d.installtime == null || d.installtime == undefined){ }}
        <a class="layui-btn layui-btn-xs" href="{:url('install')}?module={{ d.module }}">安装</a>
    {{#  } else { }}
        {{#  if(d.iscore == 0){ }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" href="{:url('uninstall')}?module={{ d.module }}">卸载</a>
        {{#  } }}
    {{#  } }}
    </script>
</div>
{/block}
{block name="script"}
<script>
layui.use(['table', 'upload'], function() {
    var table = layui.table,
        $ = layui.$,
        upload = layui.upload;
    table.render({
        elem: '#table',
        toolbar: '#toolbarDemo',
        url: '{:url("index")}',
        cols: [
            [
                { field: 'name', width: 150, title: '名称' },
                { field: 'version', width: 150, title: '版本' },
                { field: 'author', width: 150, title: '作者' },
                { field: 'introduce', title: '简介' },
                { field: 'installtime', width: 200, title: '安装时间', templet: '<div>{{#  if(d.installtime){ }} {{d.installtime}} {{#  } else { }} / {{#  } }}</div>' },
                { fixed: 'right', width: 150, title: '操作', templet: '#titleTpl' }
            ]
        ]
    });

    //执行实例
    var uploadInst = upload.render({
        elem: '#local-install',
        url: '{:url("admin/module/local")}',
        accept: 'file',
        exts: 'zip',
        done: function(res) {
            //上传完毕回调
            layer.alert(res.msg, {}, function() {
                if (res.code != 0) {
                    location.reload();
                }
            });
        },
        error: function() {
            //请求异常回调
        }
    });
});
</script>
{/block}